package com.telit.common.config;

import com.telit.common.interceptor.FileInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;


/**
 * @author zhouyu
 * @description web mvc配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final LocaleChangeInterceptor localeChangeInterceptor;
    private final FileInterceptor fileInterceptor;

    public WebMvcConfig(
            LocaleChangeInterceptor localeChangeInterceptor, FileInterceptor fileInterceptor) {
        this.localeChangeInterceptor = localeChangeInterceptor;
        this.fileInterceptor = fileInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        if (this.localeChangeInterceptor != null) {
            registry.addInterceptor(this.localeChangeInterceptor);
        }
        registry.addInterceptor(fileInterceptor);
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        // 设置允许跨域的路径
//        registry.addMapping("/**")
//                // 设置允许跨域请求的域名
//                .allowedOrigins("*")
//                // 是否允许证书 不再默认开启
//                .allowCredentials(true)
//                // 设置允许的方法
//                .allowedMethods("*")
//                // 跨域允许时间
//                .maxAge(3600);
//    }

}
